package cn.wolfcode.web.interceptor;

import cn.wolfcode.util.UserContext;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class LoginOut implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
/*       //从session中获取用户信息
        Object employee = request.getSession().getAttribute("USER_IN_SESSION");
        //判断是否有登录
        if (employee != null) {
            return true;//放行
        }
        response.sendRedirect("/login.html");*/

      if (handler instanceof HandlerMethod){
          Object employee = UserContext.getCurrentUser();
          if (employee == null) {
              response.sendRedirect("/login.html");
              return false;
          }
      }
        return true;
    }
}
